              var js_base_url = 'http://localhost/our_brgy_new/';
              /*
               * Below are common for all pages
               **/
              function weeklyBulletin() {
                var weeklyBulletin = $.ajax({
                    type:"post",
                    url:""+js_base_url+"index.php/bulletin/weeklybulletin",
                    datatype:"json",
                    success:function(data){
                        var json_bulletin = JSON.parse(data);
                        var json_bulletin_data = '';
                        if(json_bulletin.bulletin.length == 0) {
                            json_bulletin_data += '<span class="left_box_art_con">There are no bulletins yet.</span><hr />';
                        } else {
                            for(var i = 0; i < json_bulletin.bulletin.length; i++) {
                                json_bulletin_data += '<span class="left_box_art_details">'+json_bulletin.bulletin[i].schedule+'</span><br />';
                                json_bulletin_data += '<span class="left_box_art_con">'+json_bulletin.bulletin[i].details+'</span><hr />';
                            }
                        }
                        $(".left_box_con.bulletin").append(json_bulletin_data);
                    },
                    error:function() {
                        var json_bulletin_data = 'There was an error loading bulletins.<br />';
                        $(".left_box_con.bulletin").append(json_bulletin_data).css("color", "red");
                    }
                });
              }
              function latestBarangayUpdate() {
                var latestBarangayUpdate = $.ajax({
                    type:"post",
                    url:js_base_url+"index.php/news/topfivenews",
                    datatype:"json",
                    success:function(data){
                        var json_news_top = JSON.parse(data);
                        var json_news_top_data = '';
                        if(json_news_top.news.length == 0) {
                            json_news_top_data += '<span class="left_box_art_con">There are no latest news yet.</span><hr />';
                        } else {
                            for(var i = 0; i < json_news_top.news.length; i++) {
                                json_news_top_data += '<span class="left_box_art_details">'+json_news_top.news[i].posted+'</span><br />';
                                json_news_top_data += '<span class="left_box_art_con">'
                                    +'<a href="'+js_base_url+'index.php/news/macroview?news_id='
                                    +json_news_top.news[i].news_id
                                    +'">'
                                    +json_news_top.news[i].title
                                    +'</a>'
                                    +'</span><hr />';
                            }
                        }
                        $(".left_box_con.news").append(json_news_top_data);
                    },
                    error:function() {
                        var json_news_top_data = 'There was an error loading news.<br />';
                        $(".left_box_con.news").append(json_news_top_data).css("color", "red");
                    }
                });
              }
              function getProvince(e, f) {
                  var getProvince = $.ajax({
                        type:"post",
                        url:js_base_url+"index.php/general/getprovince",
                        datatype:"json",
                        success:function(data){
                            var p_v = JSON.parse(data);
                            var p_v_d = '';
                            if(p_v.provinces.length != 0) {
                                for(var i=0; i<p_v.provinces.length; i++) {
                                    if(p_v.provinces[i].province_name == e) {
                                        p_v_d += '<option value="'+p_v.provinces[i].province_id_pk+'" selected>'+p_v.provinces[i].province_name+'</option>';
                                    } else {
                                        p_v_d += '<option value="'+p_v.provinces[i].province_id_pk+'">'+p_v.provinces[i].province_name+'</option>';
                                    }
                                }
                            }
                            $("#province_val").append(p_v_d);
                            $("#prov").append(p_v_d);
                            if(f) {
                                getmunicipality(f);
                            }
                        },
                        error:function() {
                            alert('error');
                        }
                  });
              }
              function getmunicipality(e) {
                  var getMunicipality = $.ajax({
                        type:"post",
                        url:js_base_url+"index.php/general/getmunicipality",
                        data:"p_id="+$("#province_val").val(),
                        datatype:"json",
                        success:function(data){
                            var m_v = JSON.parse(data);
                            var m_v_d = '<option value="0">Municipality</option>';
                            if(m_v.municipalities.length != 0) {
                                for(var i=0; i<m_v.municipalities.length; i++) {
                                    if(m_v.municipalities[i].municipality_name == e) {
                                        m_v_d += '<option value="'+m_v.municipalities[i].municipality_id_pk+'" selected>'+m_v.municipalities[i].municipality_name+'</option>';
                                    } else {
                                        m_v_d += '<option value="'+m_v.municipalities[i].municipality_id_pk+'">'+m_v.municipalities[i].municipality_name+'</option>';
                                    }
                                }
                            }
                            $("#municipality_val").html(m_v_d);
                            $("#barangay_val").html('<option>Barangay</option>');
                        },
                        error:function() {
                            alert('error');
                        }
                  });
              }
              function getmunicipalitycustom() {
                  var getMunicipality = $.ajax({
                        type:"post",
                        url:js_base_url+"index.php/general/getmunicipality",
                        data:"p_id="+$("#prov").val(),
                        datatype:"json",
                        success:function(data){
                            var m_v = JSON.parse(data);
                            var m_v_d = '<option value="0">Select</option>';
                            if(m_v.municipalities.length != 0) {
                                for(var i=0; i<m_v.municipalities.length; i++) {
                                    m_v_d += '<option value="'+m_v.municipalities[i].municipality_id_pk+'">'+m_v.municipalities[i].municipality_name+'</option>';
                                }
                            }
                            $("#mun").html(m_v_d);
                            //$("#barangay_val").html('<option>Barangay</option>');
                        },
                        error:function() {
                            alert('error');
                        }
                  });
              }
              function getbarangay() {
                  var getbarangay = $.ajax({
                        type:"post",
                        url:js_base_url+"index.php/general/getbarangay",
                        data:"m_id="+$("#municipality_val").val(),
                        datatype:"json",
                        success:function(data){
                            var b_v = JSON.parse(data);
                            var b_v_d = '<option value="0">Barangay</option>';
                            if(b_v.barangays.length != 0) {
                                for(var i=0; i<b_v.barangays.length; i++) {
                                    b_v_d += '<option value="'+b_v.barangays[i].barangay_id_pk+'">'+b_v.barangays[i].barangay_name+'</option>';
                                }
                            }
                            $("#barangay_val").html(b_v_d);
                        },
                        error:function() {
                            alert('error');
                        }
                  });
              }
              
              /*
               * Below are applicable only to index
               **/
              function signUp() {
                var prov = $("#prov").val();
                var mun = $("#mun").val();
                var brgy_name = $("#brgy_name").val();
                var con_p = $("#con_p").val();
                var e_ad = $("#e_ad").val();
                var p_num = $("#p_num").val();
                alert(prov + "" + mun + "" + brgy_name + "" + con_p + "" + e_ad + "" + p_num);
                if(prov == 0 || mun == 0 || brgy_name == '' || con_p == '' || e_ad == '' || p_num == '') {
                    json_brgy_added_msg = "Please fill-up all fields.";
                    $("#signuperror").css("color","#f00");
                    $("#signuperror").html(json_brgy_added_msg);
                    return false;
                }
                $.ajax({
                    type:"post",
                    url:js_base_url+"index.php/general/signup",
                    data:"brgy_name="+brgy_name+"&mun_id="+mun+"&prov_id="+prov+"&con_p="+con_p+"&e_ad="+e_ad+"&p_num="+p_num,
                    success:function(data, textStatus) {
                        var json_brgy_added = JSON.parse(data);
                        if(json_brgy_added.barangayadd=="nok") {
                            $("#signuperror").css("color","#f00");
                            json_brgy_added_msg = "This barangay has either a website or signed up already.";
                        } else {
                            json_brgy_added_msg = "Your submitted is information is now subject for review and approval by your barangay.<br />Thanks for using our services!";
                            $("#signuperror").css("color","#07B313");
                        }
                        $("#signuperror").html(json_brgy_added_msg);
                    },
                    error:function(data, textStatus) {
                        $("#signuperror").css("color","#f00");
                        $("#signuperror").html("Sorry for the inconvenience.<br />There was a database connection error. Kindly retry or seek for assistance at 63 893 - 1234 for our 24 hours assistance.");
                    }
                });
                return true;
              }
              
              /*
               * Below are applicable only to index_main
               */
              function brgyDesc(act) {
                var brgyDesc = $.ajax({
                    type:"post",
                    url:""+js_base_url+"index.php/general/getdesc",
                    datatype:"json",
                    success:function(data){
                        var json_brgy_desc = JSON.parse(data);
                        var json_brgy_desc_data = '';
                        if(act == 'show') {
                            if(json_brgy_desc.desc.length == 0) {
                                json_brgy_desc_data += '<p>There is no barangay description yet.</p>';
                            } else {
                                if(json_brgy_desc.desc[0].description == '') {
                                    json_brgy_desc_data += '<p>There is no barangay description yet.</p>';
                                } else {
                                    json_brgy_desc_data += json_brgy_desc.desc[0].description;
                                }
                            }
                        } else {
                            json_brgy_desc_data += json_brgy_desc.desc[0].description;
                        }
                        if(act == 'show') {
                            $(".main_article_content.brgy_desc").append(json_brgy_desc_data);
                        } else {
                            $("textarea.general.brgy_desc").val(json_brgy_desc_data);
                        }
                    },
                    error:function() {
                        var json_brgy_desc_data = 'There was an error barangay description.<br />';
                        $(".main_article_content.brgy_desc").append(json_brgy_desc_data);
                    }
                });
              }